<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText" @tap="onreturn()">返回</block>
			<block slot="content">记录追溯</block>
		</cu-custom>

		<scroll-view scroll-x class="bg-white nav text-center fixed" :style="[{top:CustomBar + 'px'}]">
			<view class="cu-item" :class="index==TabCur?'text-blue cur':''" v-for="(item,index) in devtypelist"
				:key="index" @tap="tabSelect" :data-id="index">

				<block>
					<text :class="devtypelist[index].icon" type="default"></text>
					<text style="padding-left: 5px;" type="default">{{devtypelist[index].title}}</text>
				</block>

			</view>

		</scroll-view>
		<scroll-view scroll-y :style="[{top:CustomBar+150 + 'px'}]">
			<view class="cu-list menu-avatar" style="margin-top: 120upx;">
				<block v-if="TabCur==0">
					<view class="cu-item" style="height: 200upx;" v-for="(item,i) in uplist" :key="i">

						<view class="content" style="left: 30upx;">
							<template>
								<view>
									<view class="text-grey">出库人:{{item.addby}}</view>
								</view>
								<view>
									<view class="text-grey">商品名称:&emsp;{{item.goodname}}</view>
								</view>
								<view>
									<view class="text-grey">出库时间:&emsp;{{item.cdate}}</view>
								</view>
								<view>
									<view class="text-grey">出库数量:&emsp;{{item.num}}</view>
								</view>
							</template>

						</view>

					</view>

				</block>
				<block v-if="TabCur==1">
					<view class="cu-item" style="height: 200upx;" v-for="(item,i) in uplist2" :key="i">

						<view class="content" style="left: 30upx;">
							<template>
								<view>
									<view class="text-grey">入库人:{{item.addby}}</view>
								</view>
								<view>
									<view class="text-grey">商品名称:&emsp;{{item.goodname}}</view>
								</view>
								<view>
									<view class="text-grey">入库时间:&emsp;{{item.cdate}}</view>
								</view>
								<view>
									<view class="text-grey">入库数量:&emsp;{{item.num}}</view>
								</view>
							</template>
						</view>


					</view>

				</block>
			</view>

		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				CustomBar: this.CustomBar,
				TabCur: 0,
				username: '',
				uplist: [],
				uplist2: [],
				devtypelist: [{
						title: '出库记录',
						icon: 'cuIcon-upload'
					},
					{
						title: '入库记录',
						icon: 'cuIcon-down'
					},
				],

			}
		},
		onBackPress(options) {

			if (options.from === 'navigateBack') {
				return false;
			}
			this.backButton();
			return true;

		},
		onReady() {
			this.getorderlist();
		},
		onLoad(event) {
			this.pid = event.pid;
			console.log('当前选项卡' + this.pid);
			this.TabCur = this.pid;

		},
		methods: {
			// 全文展开收起
			toggleDescription(num) {
				//this.showText = !this.showText;
				uni.showModal({
					content: num
				})
			},
			// 返回上一页
			onreturn() {
				uni.reLaunch({
					url: '../index/index'
				});
			},
			backButton() {
				uni.navigateBack({
					delta: 1
				});
			},
			toPage(url) {
				if (!url) {
					uni.showToast({
						title: '模板未包含此页面',
						icon: "none"
					});
					return;
				}
				uni.navigateTo({
					url: url
				})
			},
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
			},
			getorderlist() {
				var _self = this;
				//读取云商品
				uniCloud.callFunction({
					name: "get_record",
					data: {
						tableName: 'GoodOutputRecord'
					}
				}).then((res) => {
					const {
						result
					} = res
					_self.uplist = result.data
				});
				uniCloud.callFunction({
					name: "get_record",
					data: {
						tableName: 'GoodInputRecord'
					}
				}).then((res) => {
					const {
						result
					} = res
					_self.uplist2 = result.data
				});
				// plus.sqlite.selectSql({
				// 	name: 'test',
				// 	sql: 'select * from  GoodOutputRecord  order by cdate desc  ',
				// 	success: (data) => {
				// 		_self.uplist = data;

				// 	},
				// 	fail: function(e) {
				// 		console.log('selectSql failed: ' + JSON.stringify(e));
				// 	}
				// });
				// plus.sqlite.selectSql({
				// 	name: 'test',
				// 	sql: 'select * from GoodInputRecord   order by cdate desc',
				// 	success: (data) => {
				// 		_self.uplist2 = data; 
				// 	},
				// 	fail: function(e) {
				// 		console.log('selectSql failed: ' + JSON.stringify(e));
				// 	}
				// });
			}
		}
	}
</script>

<style>

</style>
